<?php
class BadWord extends Module{
	function BadWord($row){
		Module::Module($row);
		if(User::is_admin()){		
			CGlobal::$website_title = 'Quản lý từ xấu';	
			switch(Url::get('cmd')){				
				case 'delete':											
					DB::query('DELETE FROM bad_words WHERE id='.AZLib::getParam('id'));
					Url::redirect_url(Url::build_all(array('chk_id','del_all','cmd','id')));
					break;
				case "edit":
				case "add":									
					require_once 'forms/edit.php';		
					$this->add_form(new EditBadWordForm());
					break;					
				default:
					require_once 'forms/list.php';
					$this->add_form(new BadWordForm());
					break;
			}
		}else{
			Url::access_denied();
		}
	}
	
	function filter_badword_show($str){
		return str_replace('*','',$str);
	}
	
	function badword_phone_type($str){
		$str_temp='';
		if($str)
		$str = preg_replace(array("'([^0-9]*)'"),array(""),$str);
		
		if($str){
			for($i=0;$i<strlen($str);$i++){
				$str_temp.=$str[$i].($i!=strlen($str)-1?'*':'');
			}
		}
		return $str_temp;
	}
				
}



/*$sql = 'SELECT conf_val FROM configs WHERE id=5'; 
$row = DB::fetch($sql);
$str_tmp = str_replace(',','"),("',$row['conf_val']);
$str_tmp = '("'.$str_tmp.'")';
echo $str_tmp;

DB::query('INSERT INTO bad_words (contents) VALUES '.$str_tmp);*/

/*$sql = "SELECT id, contents FROM bad_words";
$result = DB::query($sql);
while ($row=mysql_fetch_assoc($result)){
	DB::query("UPDATE bad_words SET checksum='".md5($row["contents"])."' WHERE id=".$row["id"]);
}*/	

?>